package com.qingke.exercise;

import java.io.IOException;
import java.util.List;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

public class JDomTest {

	public static void main(String[] args) {
		try {
			long start = System.currentTimeMillis();
			
			
			SAXBuilder builder = new SAXBuilder();
			Document document = builder.build("student.xml");
			Element root = document.getRootElement();
			List<Element> children  = root.getChildren();
			
			for(Element child:children){
				if(!"student".equals(child.getName())){
					continue;
				}
				System.out.println("------Student------");
				System.out.println("id:"+child.getAttributeValue("id"));
				System.out.println("name:"+child.getChildText("name"));
				System.out.println("gender:"+child.getChildText("gender"));
				System.out.println("age:"+child.getChildText("age"));
			}
			long end = System.currentTimeMillis();
			System.out.println("cost:"+(end-start)+"ms");
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}

}
